<?php
global $Config;
require_once($Config->WebCMSRoot.'Base/Data.mysql.php');

Class ImageData extends db
{
	
	function ImageData()
	{
		parent::db();

		$this->tableName = 'images';
		
		$this->AddMap("ID", "id", "id", DATATYPE_INTEGER, true);
		$this->AddMap("File", "file", "file", DATATYPE_TEXT, true);
		$this->AddMap("Thumbnail", "thumbnail", "thumbnail", DATATYPE_TEXT, false);
		$this->AddMap("Width", "width", "width", DATATYPE_INTEGER, false);
		$this->AddMap("Height", "height", "height", DATATYPE_INTEGER, false);
		$this->AddMap("ThumbnailWidth", "thumbWidth", "thumbWidth", DATATYPE_INTEGER, false);
		$this->AddMap("ThumbnailHeight", "thumbHeight", "thumbHeight", DATATYPE_INTEGER, false);
		$this->AddMap("Module", "module", "module", DATATYPE_TEXT, true);
		}
  
	function Retrieve(&$image)
	{
		$sql  = "SELECT ";
		$sql .= $this->GetFieldList();
		$sql .= "FROM " . $this->GetTableName() . " ";
		$sql .= $this->GetWhereClause($image);
		$sql .= "ORDER BY file ";

		$image->Collection = array();

	    $rows = $this->Select($sql);
	    foreach($rows as $key=>$row)
	    {
			$image->Collection[] = $this->FillRow($row);
		}
	}
  
	function Update(&$image)
	{
		if (isset($image->ID) && !empty($image->ID) && $image->ID > 0)
		{
			$sql  = "UPDATE " . $this->GetTableName(false);
			$sql .= $this->GetUpdateList($image);
			$sql .= "WHERE id=" . $image->ID;
		}
		else
		{
			$sql  = "INSERT INTO " . $this->GetTableName(false);
			$sql .= $this->GetInsertFieldList();
			$sql .= $this->GetInsertValueList(&$image);
		}

	    $result = $this->Execute($sql);

		if (!isset($image->ID) || empty($image->ID) || $image->ID <= 0)
		{
			$image->ID = $result;
		}
	}
  
	function FillRow($row)
	{
		$image = new ImageModel();
		
		parent::FillRow(&$image, &$row);
		
		return $image;
	}
	
	function GetFieldList()
	{
		parent::GetFieldList(&$select);
		
		return $select;
	}
}
?>
